<html>
<head><meta charset="utf-8"><title>macro_exports and std::prelude · rustdoc · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/index.html">rustdoc</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/macro_exports.20and.20std.3A.3Aprelude.html">macro_exports and std::prelude</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="243055032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/macro_exports%20and%20std%3A%3Aprelude/near/243055032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/macro_exports.20and.20std.3A.3Aprelude.html#243055032">(Jun 17 2021 at 17:37)</a>:</h4>
<p>It's pretty confusing that no exported macros show up or are mentioned on <a href="https://doc.rust-lang.org/std/prelude/v1/index.html">https://doc.rust-lang.org/std/prelude/v1/index.html</a> given that there are apparently 22 exported macros from the prelude (<a href="https://github.com/rust-lang/rfcs/blob/master/text/3114-prelude-2021.md#prior-art">https://github.com/rust-lang/rfcs/blob/master/text/3114-prelude-2021.md#prior-art</a>)</p>



<a name="243055161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/macro_exports%20and%20std%3A%3Aprelude/near/243055161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/macro_exports.20and.20std.3A.3Aprelude.html#243055161">(Jun 17 2021 at 17:38)</a>:</h4>
<p>The page at <a href="https://doc.rust-lang.org/std/prelude/index.html">https://doc.rust-lang.org/std/prelude/index.html</a> also does not mention any</p>



<a name="243066554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/macro_exports%20and%20std%3A%3Aprelude/near/243066554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/macro_exports.20and.20std.3A.3Aprelude.html#243066554">(Jun 17 2021 at 18:56)</a>:</h4>
<p>I don't understand what you mean: on the site you linked, we can see several macros; on my machine, <code>curl 'https://doc.rust-lang.org/std/prelude/v1/index.html' 2&gt;&amp;- | grep -o macro\\. | wc -l</code> yields 31, for instance.</p>



<a name="243066668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/macro_exports%20and%20std%3A%3Aprelude/near/243066668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/macro_exports.20and.20std.3A.3Aprelude.html#243066668">(Jun 17 2021 at 18:57)</a>:</h4>
<p><a href="/user_uploads/4715/hFVxuZ7khqQnEMAjTRKfw6eR/Screen-Shot-2021-06-17-at-20.57.45.png">Screen-Shot-2021-06-17-at-20.57.45.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/hFVxuZ7khqQnEMAjTRKfw6eR/Screen-Shot-2021-06-17-at-20.57.45.png" title="Screen-Shot-2021-06-17-at-20.57.45.png"><img src="/user_uploads/4715/hFVxuZ7khqQnEMAjTRKfw6eR/Screen-Shot-2021-06-17-at-20.57.45.png"></a></div>



<a name="243067326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/macro_exports%20and%20std%3A%3Aprelude/near/243067326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremiah Senkpiel <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/macro_exports.20and.20std.3A.3Aprelude.html#243067326">(Jun 17 2021 at 19:02)</a>:</h4>
<p>oh. True. Guess that's my bad in reading them.</p>
<p>Why is this less macros than is actually in the global scope though? Is it because the others are in <code>core</code>?</p>
<p>Also uh, maybe re-exports could be sorted/labeled better ...</p>



<a name="243069524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/266220-rustdoc/topic/macro_exports%20and%20std%3A%3Aprelude/near/243069524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/266220-rustdoc/topic/macro_exports.20and.20std.3A.3Aprelude.html#243069524">(Jun 17 2021 at 19:17)</a>:</h4>
<blockquote>
<p>Also uh, maybe re-exports could be sorted/labeled better ...</p>
</blockquote>
<p>Yeah, I guess rustdoc is ordering the re-exported items by <em>nature</em> of the reexported item rather than mixing them all up</p>
<blockquote>
<p>than in the global scope</p>
</blockquote>
<p>Oh, I see what you mean now: macros such as <code>println!</code> (which are <code>#[macro_export] macro_rules!</code> macros) are then into "the prelude" not by virtue of the <code>v1</code> prelude or whatnot, but actually because non-<code>#![no_std]</code> crates import the <code>std</code> crate through an implicit <code>#[macro_use] extern crate std;</code> statement (and <code>#[macro_use]</code> pulls the <code>#[macro_export]</code>ed macros into the prelude of the current crate).</p>
<ul>
<li>This is actually an issue since it circumvents the "versioned" prelude design, good catch! (That is, a <code>#[macro_export]</code>-ed <code>macro_rules!</code> macro defined in <code>std</code> acts, in practice, as if present in all preludes, present, and future. It thus seems like a bigger commitment than initially anticipated, and any future macros added to the language ought to be <code>macro</code> macros so as to properly contain their prelude-ness)</li>
</ul>
<p>This means that there should be a funny way to observe what you mean:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![no_std]</span><span class="w"></span>

<span class="k">extern</span><span class="w"> </span><span class="k">crate</span><span class="w"> </span><span class="n">std</span><span class="p">;</span><span class="w"></span>

<span class="k">use</span><span class="w"> </span>::<span class="n">std</span>::<span class="n">prelude</span>::<span class="n">v1</span>::<span class="o">*</span><span class="p">;</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="w"> </span><span class="p">()</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="fm">format_args!</span><span class="p">(</span><span class="s">""</span><span class="p">);</span><span class="w"> </span><span class="c1">// OK</span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="fm">format!</span><span class="p">(</span><span class="s">""</span><span class="p">);</span><span class="w"> </span><span class="c1">// Error</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=5c6e3f21240f1c6a8dbb4dce63c570e7">yields</a>:</p>
<div class="codehilite" data-code-language="Text only"><pre><span></span><code>error: cannot find macro `format` in this scope
  --&gt; src/main.rs:10:13
   |
10 |     let _ = format!(""); // Error
   |             ^^^^^^
   |
   = note: consider importing this macro:
           std::format
</code></pre></div>
<p>(and the inverse would be to do <code>#[macro_use] extern crate std;</code> without the prelude import)</p>
<p>This is thus not a docs issue, but a libs one.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>